package com.ruoyi.business.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.business.domain.LocationInfo;
import com.ruoyi.business.domain.NumberManagement;
import com.ruoyi.business.domain.TextReader;
import com.ruoyi.business.mapper.LocationInfoMapper;
import com.ruoyi.business.mapper.NumberManagementMapper;
import com.ruoyi.business.service.ILocationInfoService;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.BigDecimalUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.python.antlr.ast.If;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 位置信息Service业务层处理
 *
 * @author yangmeng
 * @date 2023-06-09
 */
@Service
public class LocationInfoServiceImpl implements ILocationInfoService {

    @Autowired
    private LocationInfoMapper locationInfoMapper;

    @Autowired
    private NumberManagementMapper numberManagementMapper;

    /**
     * 查询位置信息
     *
     * @param locationId 位置信息主键
     * @return 位置信息
     */
    @Override
    public LocationInfo selectLocationInfoByLocationId(Long locationId) {
        return locationInfoMapper.selectLocationInfoByLocationId(locationId);
    }

    /**
     * 查询位置信息列表
     *
     * @param locationInfo 位置信息
     * @return 位置信息
     */
    @Override
    public List<LocationInfo> selectLocationInfoList(LocationInfo locationInfo) {
        return locationInfoMapper.selectLocationInfoList(locationInfo);
    }

    /**
     * 新增位置信息
     *
     * @param locationInfo 位置信息
     * @return 结果
     */
    @Override
    public List<LocationInfo> insertLocationInfo(LocationInfo locationInfo) {
        setCoordinateFive(locationInfo);
        if (locationInfo.getName().contains("~")) {
            locationInfo.setRemark("0");
        }
        Long pid = locationInfo.getPid();
        if (pid == 0L) {
            locationInfo.setAncestors("0,");
        } else {
            LocationInfo parent = locationInfoMapper.selectLocationInfoByLocationId(pid);
            locationInfo.setAncestors(parent.getAncestors() + "," + parent.getLocationId());
        }
        locationInfoMapper.insertLocationInfo(locationInfo);
        automatic(locationInfo);
        LocationInfo locationInfoQuery = new LocationInfo();
        locationInfoQuery.setLocationId(locationInfo.getLocationId());
        List<LocationInfo> locationInfos = locationInfoMapper.selectLocationInfoList(locationInfoQuery);
        locationInfos.add(locationInfo);
        return locationInfos;
    }

    /**
     * 修改位置信息
     *
     * @param locationInfo 位置信息
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<LocationInfo> updateLocationInfo(LocationInfo locationInfo) {
        locationInfoMapper.updateLocationInfo(locationInfo);
        LocationInfo infoDb = locationInfoMapper.selectLocationInfoByLocationId(locationInfo.getLocationId());
        if (StringUtils.isEmpty(infoDb.getCoordinateOne())) {
            List<LocationInfo> locationInfos = locationInfoMapper.selectChildrenLocationInfoById(locationInfo.getLocationId());
            for (LocationInfo info : locationInfos) {
                setCoordinateFive(info);
                locationInfoMapper.deleteLocationInfoByAncestors(info.getLocationId());
                automatic(info);
            }
        } else {
            locationInfoMapper.deleteLocationInfoByAncestors(locationInfo.getLocationId());
            setCoordinateFive(locationInfo);
            automatic(infoDb);
        }
        NumberManagement numberManagement = new NumberManagement();
        numberManagement.setNumberId(locationInfo.getNumberId());
        numberManagement.setUpdateTime(DateUtils.getNowDate());
        numberManagement.setUpdateBy(SecurityUtils.getUserId());
        numberManagement.setStatus("1");
        numberManagementMapper.updateNumberManagement(numberManagement);
        LocationInfo info = locationInfoMapper.selectLocationInfoByLocationId(locationInfo.getLocationId());
        LocationInfo locationInfoQuery = new LocationInfo();
        locationInfoQuery.setLocationId(locationInfo.getLocationId());
        List<LocationInfo> locationInfos = locationInfoMapper.selectLocationInfoList(locationInfoQuery);
        locationInfos.add(info);
        return locationInfos;
    }

    /**
     * 批量删除位置信息
     *
     * @param locationIds 需要删除的位置信息主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteLocationInfoByLocationIds(Long[] locationIds) {
        for (Long locationId : locationIds) {
            locationInfoMapper.deleteLocationInfoByAncestors(locationId);
        }
        return locationInfoMapper.deleteLocationInfoByLocationIds(locationIds);
    }

    /**
     * 删除位置信息信息
     *
     * @param locationId 位置信息主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteLocationInfoByLocationId(Long locationId) {
        locationInfoMapper.deleteLocationInfoByAncestors(locationId);
        return locationInfoMapper.deleteLocationInfoByLocationId(locationId);
    }

    /**
     * limit查询
     *
     * @param numberId
     * @return
     */
    @Override
    public LocationInfo selectLocationInfoByNumberId(Long numberId) {
        return locationInfoMapper.selectLocationInfoByNumberId(numberId);
    }

    public void automatic(LocationInfo infoDb) {
        int y = infoDb.getBracketLine();
        int x = infoDb.getBracketRow();
        String assemblyOrder = infoDb.getAssemblyOrder();
        List<TextReader> textReaderList = new ArrayList<>();
        TextReader textReader1 = new TextReader();
        String[] coordinate1 = infoDb.getCoordinateOne().split(",");
        textReader1.setLongitude(coordinate1[0]);
        textReader1.setLatitude(coordinate1[1]);
        textReader1.setElevation(coordinate1[2]);
        textReaderList.add(textReader1);
        TextReader textReader2 = new TextReader();
        String[] coordinate2 = infoDb.getCoordinateTwo().split(",");
        textReader2.setLongitude(coordinate2[0]);
        textReader2.setLatitude(coordinate2[1]);
        textReader2.setElevation(coordinate2[2]);
        textReaderList.add(textReader2);
        TextReader textReader3 = new TextReader();
        String[] coordinate3 = infoDb.getCoordinateThree().split(",");
        textReader3.setLongitude(coordinate3[0]);
        textReader3.setLatitude(coordinate3[1]);
        textReader3.setElevation(coordinate3[2]);
        textReaderList.add(textReader3);
        TextReader textReader4 = new TextReader();
        String[] coordinate4 = infoDb.getCoordinateFour().split(",");
        textReader4.setLongitude(coordinate4[0]);
        textReader4.setLatitude(coordinate4[1]);
        textReader4.setElevation(coordinate4[2]);
        textReaderList.add(textReader4);
        TextReader[][] array = calcGPS(y, x, textReaderList);
        if (infoDb.getName().contains("~")) {
            // 组串编号
            seriesNumber(textReaderList, infoDb);
        } else {
            int initialValue = 1;
            int endValue = x;
            infoDb.setBracketLine(1);
            infoDb.setBracketRow(x);
            if ("0".equals(assemblyOrder) || "1".equals(assemblyOrder)) {
                for (int i = 1; i <= y; i++) {
                    infoDb.setInitialValue(initialValue);
                    infoDb.setEndValue(endValue);
                    List<TextReader> list = new ArrayList<>();
                    list.add(array[y - i][0]);
                    list.add(array[y - i][x]);
                    list.add(array[y - i + 1][0]);
                    list.add(array[y - i + 1][x]);
                    assemblyNumber(list, infoDb);
                    initialValue += x;
                    endValue += x;
                }
            } else if ("2".equals(assemblyOrder) || "3".equals(assemblyOrder)) {
                List<TextReader> textReaderList1 = new ArrayList<>();
                textReaderList1.add(array[1][0]);
                textReaderList1.add(array[1][x]);
                textReaderList1.add(array[2][0]);
                textReaderList1.add(array[2][x]);
                infoDb.setInitialValue(1);
                infoDb.setEndValue(x);
                if ("2".equals(assemblyOrder)) {
                    infoDb.setAssemblyOrder("0");
                } else if ("3".equals(assemblyOrder)) {
                    infoDb.setAssemblyOrder("1");
                }
                infoDb.setBracketLine(1);
                assemblyNumber(textReaderList1, infoDb);
                List<TextReader> textReaderList2 = new ArrayList<>();
                textReaderList2.add(array[1][0]);
                textReaderList2.add(array[1][x]);
                textReaderList2.add(array[0][0]);
                textReaderList2.add(array[0][x]);
                infoDb.setInitialValue(x + 1);
                infoDb.setEndValue(x + x);
                if ("2".equals(assemblyOrder)) {
                    infoDb.setAssemblyOrder("1");
                } else if ("3".equals(assemblyOrder)) {
                    infoDb.setAssemblyOrder("0");
                }
                assemblyNumber(textReaderList2, infoDb);
            }
        }
    }

    /**
     * 经纬度坐标 x,y轴坐标
     *
     * @param col 行数 y
     * @param row 列数 x
     * @param ld  起始坐标点
     * @param ru  结束坐标点
     * @return
     */
    public TextReader[][] calcGPS(Integer col, Integer row, List<TextReader> textReaderList) {
        List<TextReader> sortList = textReaderList.stream().sorted(Comparator.comparing(TextReader::getLatitude)).collect(Collectors.toList());
        TextReader ld = new TextReader();
        TextReader rd = new TextReader();
        TextReader lu = new TextReader();
        if (Convert.toDouble(sortList.get(0).getLongitude()) < Convert.toDouble(sortList.get(1).getLongitude())) {
            ld = sortList.get(0);
            rd = sortList.get(1);
        } else {
            ld = sortList.get(1);
            rd = sortList.get(0);
        }
        if (Convert.toDouble(sortList.get(2).getLongitude()) < Convert.toDouble(sortList.get(3).getLongitude())) {
            lu = sortList.get(2);
        } else {
            lu = sortList.get(3);
        }
        // 加法 add()函数 减法subtract()函数 乘法multiply()函数 除法divide()函数 绝对值abs()函数
        TextReader[][] array = new TextReader[col + 1][row + 1];
        BigDecimal ld_la = new BigDecimal(ld.getLatitude());
        BigDecimal lu_la = new BigDecimal(lu.getLatitude());
        BigDecimal ld_lo = new BigDecimal(ld.getLongitude());
        BigDecimal rd_lo = new BigDecimal(rd.getLongitude());

        BigDecimal lu_lo = new BigDecimal(lu.getLongitude());
        BigDecimal rd_la = new BigDecimal(rd.getLatitude());

        BigDecimal col_ = new BigDecimal(col);
        BigDecimal row_ = new BigDecimal(row);
        // 纬度偏移量
        BigDecimal offset_la = rd_la.subtract(ld_la).divide(row_, 20, BigDecimal.ROUND_HALF_UP);
        // 经度偏移量
        BigDecimal offset_lo = lu_lo.subtract(ld_lo).divide(col_, 20, BigDecimal.ROUND_HALF_UP);

        for (int i = 0; i <= col; i++) {
            for (int j = 0; j <= row; j++) {
                TextReader temp = new TextReader();
                BigDecimal i_ = new BigDecimal(i);
                BigDecimal j_ = new BigDecimal(j);
                BigDecimal a = lu_la.subtract(ld_la).multiply(i_).divide(col_, 20, BigDecimal.ROUND_HALF_UP).add(ld_la).add(j_.multiply(offset_la));
                BigDecimal b = rd_lo.subtract(ld_lo).multiply(j_).divide(row_, 20, BigDecimal.ROUND_HALF_UP).add(ld_lo).add(i_.multiply(offset_lo));
                temp.setLatitude(a.toString());
                temp.setLongitude(b.toString());
                temp.setElevation("0");
                temp.setCoordinate(b + "," + a + ",0");
                array[i][j] = temp;
            }
        }
        return array;
    }

    public void setCoordinateFive(LocationInfo locationInfo) {
        if (StringUtils.isNotEmpty(locationInfo.getCoordinateOne()) && StringUtils.isNotEmpty(locationInfo.getCoordinateTwo()) && StringUtils.isNotEmpty(locationInfo.getCoordinateThree()) && StringUtils.isNotEmpty(locationInfo.getCoordinateFour())) {
            String[] coordinate1 = locationInfo.getCoordinateOne().split(",");
            String[] coordinate2 = locationInfo.getCoordinateTwo().split(",");
            String[] coordinate3 = locationInfo.getCoordinateThree().split(",");
            String[] coordinate4 = locationInfo.getCoordinateFour().split(",");
            locationInfo.setCoordinateFive(BigDecimalUtils.add(coordinate1[0], coordinate2[0], coordinate3[0], coordinate4[0]) + "," +
                    BigDecimalUtils.add(coordinate1[1], coordinate2[1], coordinate3[1], coordinate4[1]) + ",0");
        }
    }

    public void numberType1(List<TextReader> textReaderList, String key, NumberManagement numberManagement) {
        // 支架列数
//        Integer x = numberManagement.getBracketColumn();
        // 支架行数
//        Integer y = numberManagement.getBracketRow();
        String[] arr = key.split("@");
        int x = arr.length;
        int y = 1;
        TextReader[][] array = calcGPS(y, x, textReaderList);
        for (int i = 0; i < arr.length; i++) {
            List<TextReader> textReaderList1 = new ArrayList<>();
             //坐标1
            textReaderList1.add(array[0][i]);
            // 坐标2
            textReaderList1.add(array[0][i+1]);
            // 坐标3
            textReaderList1.add(array[y][i]);
            // 坐标4
            textReaderList1.add(array[y][i+1]);
            System.out.println("=======" + arr[0] + "=======");
            seriesNumber2(textReaderList1, 2, 10, numberManagement, arr[i]);
        }


//        TextReader[][] array = calcGPS(y, x, textReaderList);
//        int l1 = numberManagement.getL1();
//        int l2 = numberManagement.getL2();
//        int r1 = numberManagement.getR1();
//        int r2 = numberManagement.getR2();
//        for (int i = 0; i < arr.length; i++) {
//            if (i == 0) {
//                // 组串1
//                List<TextReader> textReaderList1 = new ArrayList<>();
//                // 坐标1
//                textReaderList1.add(array[0][0]);
//                // 坐标2
//                textReaderList1.add(array[0][r1]);
//                // 坐标3
//                textReaderList1.add(array[y][0]);
//                // 坐标4
//                textReaderList1.add(array[y][r1]);
//                System.out.println("=======" + arr[0] + "=======");
//                seriesNumber2(textReaderList1, l1, r1, numberManagement, arr[0]);
//            }
//            if (i == 1) {
//                // 组串2
//                List<TextReader> textReaderList2 = new ArrayList<>();
//                // 坐标1
//                textReaderList2.add(array[0][r1]);
//                // 坐标2
//                textReaderList2.add(array[0][r1 + r2]);
//                // 坐标3
//                textReaderList2.add(array[y][r1]);
//                // 坐标4
//                textReaderList2.add(array[y][r1 + r2]);
//                System.out.println("=======" + arr[1] + "=======");
//                seriesNumber2(textReaderList2, l2, r2, numberManagement, arr[1]);
//            }
//        }
    }


    public void seriesNumber2(List<TextReader> textReaderList, int y, int x, NumberManagement numberManagement, String name) {
        TextReader[][] array = calcGPS(y, x, textReaderList);
        int index = name.indexOf("N");
        if (index > 0 && name.charAt(index - 1) != '-') {
            name = name.replace("N", "-N");
        }
        String[] nameArr = name.split("-");
        StringBuffer ancestors = new StringBuffer();
        ancestors.append(0).append(",");
        String pName = "";
        Long pid = 0L;
        for (int i = 0; i < nameArr.length; i++) {
            LocationInfo locationInfo = new LocationInfo();
            if (i == nameArr.length - 1) {
                locationInfo.setName(pName + nameArr[i]);
                locationInfo.setNumberId(numberManagement.getNumberId());
                locationInfo.setBracketLine(y);
                locationInfo.setBracketRow(x);
                locationInfo.setAncestors(ancestors.toString());
                locationInfo.setPid(pid);
                locationInfo.setCoordinateOne(textReaderList.get(0).getCoordinate());
                locationInfo.setCoordinateTwo(textReaderList.get(1).getCoordinate());
                locationInfo.setCoordinateThree(textReaderList.get(2).getCoordinate());
                locationInfo.setCoordinateFour(textReaderList.get(3).getCoordinate());
                locationInfo.setCoordinateFive(BigDecimalUtils.add(textReaderList.get(0).getLongitude(), textReaderList.get(1).getLongitude(), textReaderList.get(2).getLongitude(), textReaderList.get(3).getLongitude()) + "," + BigDecimalUtils.add(textReaderList.get(0).getLatitude(), textReaderList.get(1).getLatitude(), textReaderList.get(2).getLatitude(), textReaderList.get(3).getLatitude()) + ",0");
                locationInfo.setRemark("0");
                locationInfoMapper.insertLocationInfo(locationInfo);
                // 组件编号
                List<TextReader> textReaderList1 = new ArrayList<>();
                textReaderList1.add(array[1][0]);
                textReaderList1.add(array[1][x]);
                textReaderList1.add(array[2][0]);
                textReaderList1.add(array[2][x]);
                locationInfo.setInitialValue(1);
                locationInfo.setEndValue(x);
                locationInfo.setAssemblyOrder("1");
                locationInfo.setBracketLine(1);
                assemblyNumber(textReaderList1, locationInfo);
                List<TextReader> textReaderList2 = new ArrayList<>();
                textReaderList2.add(array[1][0]);
                textReaderList2.add(array[1][x]);
                textReaderList2.add(array[0][0]);
                textReaderList2.add(array[0][x]);
                locationInfo.setInitialValue(x + 1);
                locationInfo.setEndValue(x + x);
                locationInfo.setAssemblyOrder("0");
                assemblyNumber(textReaderList2, locationInfo);
            } else {
                locationInfo.setName(pName + nameArr[i]);
                locationInfo.setNumberId(numberManagement.getNumberId());
                locationInfo.setBracketLine(y);
                locationInfo.setBracketRow(x);
                locationInfo.setAncestors(ancestors.toString());
                locationInfo.setPid(pid);
                LocationInfo locationInfoDb = locationInfoMapper.checkName(locationInfo);
                if (locationInfoDb == null) {
                    locationInfoMapper.insertLocationInfo(locationInfo);
                    pid = locationInfo.getLocationId();
                    ancestors.append(locationInfo.getLocationId()).append(",");
                    pName = locationInfo.getName() + "-";
                } else {
                    pid = locationInfoDb.getLocationId();
                    ancestors.append(locationInfoDb.getLocationId()).append(",");
                    pName = locationInfoDb.getName() + "-";
                }
            }
        }
    }

    /**
     * 组串编号
     *
     * @param textReaderList 坐标点集合
     * @param locationInfo   父级对象
     */
    public void seriesNumber(List<TextReader> textReaderList, LocationInfo locationInfo) {
        // 支架列数
        int x = locationInfo.getBracketRow();
        // 支架行数
        int y = locationInfo.getBracketLine();
        // 组件编号顺序
        String seriesOrder = locationInfo.getSeriesOrder();
        // 获取经纬度坐标信息
        TextReader[][] array = calcGPS(y, x, textReaderList);
        String name = locationInfo.getName();
        String pName = name.substring(0, name.lastIndexOf("-") + 1);
        String number = name.substring(name.lastIndexOf("-") + 1);
        String[] numbers = number.split("~");
        String ancestors = locationInfo.getAncestors() + "," + locationInfo.getLocationId();
        // 组串编号 0：从上到下，1：从下到上，2：从左到右，3从右到左
        for (int i1 = Convert.toInt(numbers[0]); i1 <= Convert.toInt(numbers[1]); i1++) {
            int k = i1 - Convert.toInt(numbers[0]);
            LocationInfo locationInfoA = new LocationInfo();
            String name_1 = Convert.toStr(i1);
            if (i1 < 10) {
                name_1 = "0" + i1;
            }
            locationInfoA.setName(pName + name_1);
            locationInfoA.setNumberId(locationInfo.getNumberId());
            locationInfoA.setBracketLine(1);
            locationInfoA.setBracketRow(locationInfo.getBracketRow());
            locationInfoA.setAncestors(ancestors);
            locationInfoA.setPid(locationInfo.getLocationId());
            locationInfoA.setType(locationInfo.getType());
            locationInfoA.setSeriesOrder(locationInfo.getSeriesOrder());
            locationInfoA.setAssemblyOrder(locationInfo.getAssemblyOrder());
            locationInfoA.setInitialValue(1);
            locationInfoA.setEndValue(x);
            int index1 = 0;
            int index2 = 0;
            // 组串编号 0：从上到下，1：从下到上
            if ("0".equals(seriesOrder)) {
                index1 = y - k;
                index2 = y - k - 1;
            } else if ("1".equals(seriesOrder)) {
                index1 = k;
                index2 = k + 1;
            }
            locationInfoA.setCoordinateOne(array[index1][0].getLongitude() + "," + array[index1][0].getLatitude() + ",0");
            locationInfoA.setCoordinateTwo(array[index2][0].getLongitude() + "," + array[index2][0].getLatitude() + ",0");
            locationInfoA.setCoordinateThree(array[index1][x].getLongitude() + "," + array[index1][x].getLatitude() + ",0");
            locationInfoA.setCoordinateFour(array[index2][x].getLongitude() + "," + array[index2][x].getLatitude() + "," + "0");
            locationInfoA.setCoordinateFive(BigDecimalUtils.add(array[index1][0].getLongitude(), array[index2][0].getLongitude(), array[index1][x].getLongitude(), array[index2][x].getLongitude()) + "," +
                    BigDecimalUtils.add(array[index1][0].getLatitude(), array[index2][0].getLatitude(), array[index1][x].getLatitude(), array[index2][x].getLatitude()) + ",0");
            locationInfoMapper.insertLocationInfo(locationInfoA);
            List<TextReader> textReaders = new ArrayList<>();
            textReaders.add(array[index1][0]);
            textReaders.add(array[index2][0]);
            textReaders.add(array[index1][x]);
            textReaders.add(array[index2][x]);
            // 组件编号
            assemblyNumber(textReaders, locationInfoA);
        }
    }

    /**
     * 组件编号
     *
     * @param textReaderList 坐标点集合
     * @param locationInfo   组串对象
     */
    public void assemblyNumber(List<TextReader> textReaderList, LocationInfo locationInfo) {
        int x = locationInfo.getBracketRow();
        int y = locationInfo.getBracketLine();
        Integer initialValue = locationInfo.getInitialValue();
        Integer endValue = locationInfo.getEndValue();
        // 获取经纬度坐标信息
        TextReader[][] array = calcGPS(y, x, textReaderList);
        for (int i = initialValue; i <= endValue; i++) {
            String name = Convert.toStr(i);
            if (i < 10) {
                name = "0" + name;
            }
            int index1 = 0;
            int index2 = 1;
            int index3 = 1;
            int index4 = 1;
            // 组件编号顺序：0从左到右，1从右到左
            if ("0".equals(locationInfo.getAssemblyOrder())) {
                index3 = i - initialValue + 1;
                index4 = i - initialValue;
            } else if ("1".equals(locationInfo.getAssemblyOrder())) {
                index3 = endValue - i + 1;
                index4 = endValue - i;
            }
            LocationInfo locationInfoB = new LocationInfo();
            locationInfoB.setName(locationInfo.getName() + "-" + name);
            locationInfoB.setNumberId(locationInfo.getNumberId());
            locationInfoB.setBracketLine(1);
            locationInfoB.setBracketRow(1);
            locationInfoB.setSeriesOrder(locationInfo.getSeriesOrder());
            locationInfoB.setAssemblyOrder(locationInfo.getAssemblyOrder());
            locationInfoB.setAncestors(locationInfo.getAncestors() + "," + locationInfo.getLocationId());
            locationInfoB.setPid(locationInfo.getLocationId());
            locationInfoB.setCoordinateOne(array[index1][index3].getLongitude() + "," + array[index1][index3].getLatitude() + "," + array[index1][index3].getElevation());
            locationInfoB.setCoordinateTwo(array[index1][index4].getLongitude() + "," + array[index1][index4].getLatitude() + "," + array[index1][index4].getElevation());
            locationInfoB.setCoordinateThree(array[index2][index3].getLongitude() + "," + array[index2][index3].getLatitude() + "," + array[index2][index3].getElevation());
            locationInfoB.setCoordinateFour(array[index2][index4].getLongitude() + "," + array[index2][index4].getLatitude() + "," + array[index2][index4].getElevation());
            locationInfoB.setCoordinateFive(BigDecimalUtils.add(array[index1][index3].getLongitude(), array[index2][index3].getLongitude(), array[index1][index4].getLongitude(), array[index2][index4].getLongitude()) + "," +
                    BigDecimalUtils.add(array[index1][index3].getLatitude(), array[index2][index3].getLatitude(), array[index1][index4].getLatitude(), array[index2][index4].getLatitude()) + ",0");
            locationInfoMapper.insertLocationInfo(locationInfoB);
        }
    }
}
